package cn.edu.qfnu.oj.entity;

import cn.edu.qfnu.oj.entity.enums.Difficulty;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@DynamicUpdate
public class Level implements Serializable {

    private Integer id;  // 等级ID
    private Difficulty commonLevel;  // 学生的普通等级
    private Integer common_exp; // 学生的普通经验值
    private Difficulty ACM_level;  // 学生的ACM等级
    private Integer ACM_exp; // 学生的ACM经验值
    private Student student; //学生与等级是一对一关系

    public Level() {}

    public Level(Student student) {
        this.commonLevel = Difficulty.BRONZE;
        this.ACM_level = Difficulty.BRONZE;
        this.common_exp = 0;
        this.ACM_exp = 0;
        this.student = student;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "common_level")
    @Enumerated(value = EnumType.STRING)
    public Difficulty getCommonLevel() {
        return commonLevel;
    }

    public void setCommonLevel(Difficulty commonLevel) {
        this.commonLevel = commonLevel;
    }

    @Column(name = "common_exp")
    public Integer getCommon_exp() {
        return common_exp;
    }

    public void setCommon_exp(Integer common_exp) {
        this.common_exp = common_exp;
    }

    @Column(name = "ACM_level")
    @Enumerated(value = EnumType.STRING)
    public  Difficulty getACM_level() {
        return ACM_level;
    }

    public void setACM_level(Difficulty ACM_level) {
        this.ACM_level = ACM_level;
    }

    @Column(name = "ACM_exp")
    public Integer getACM_exp() {
        return ACM_exp;
    }

    public void setACM_exp(Integer ACM_exp) {
        this.ACM_exp = ACM_exp;
    }

    @OneToOne // 维护段位与学生的一对一关系
    @JoinColumn(name = "student_id", referencedColumnName = "student_id")
    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }
}
